Repository navigation
feat(storage): record gcp.storage.client.ttfb for HTTP unary and upload requests - #15066
Draft
nidhiii-27 wants to merge 1 commit into
Draft
nidhiii-27 wants to merge 1 commit into
nidhiii-27 wants to merge 1 commit into
Conversation
…ad requests Extend HTTP `gcp.storage.client.ttfb` instrumentation in `StorageHttpMetricsInterceptor` beyond media downloads so all HTTP responses (unary metadata/control operations, direct/multipart uploads, resumable upload session open/chunk/query requests, and outer `/batch/storage/v1` requests) record Time To First Byte when response headers arrive: - Add package-private `StorageMetricsContext.makeCurrent()` / `StorageMetricsContext.current()` combining a `ThreadLocal<StorageMetricsContext>` with `otelContext.makeCurrent()` in a single `Scope`, and activate it in `Retrying.DefaultRetrier.run` and `Retrying.AttemptOnceRetrier.run`. - Resolve `gcp.storage.operation` and `otelContext` in `StorageHttpMetricsInterceptor` from `StorageMetricsContext.current()` first, falling back to `isMediaDownloadRequest`, `isMediaUploadRequest`, and `ROUTE_OPERATIONS` (honoring `X-HTTP-Method-Override` for `NetHttpTransport` `PATCH` and long `GET` requests) for context-free transport calls (PCU part hooks, `BlobWriteSession`, `StorageBatch`). - Keep `setIOExceptionHandler` recording `http.client.request.duration` only when no HTTP response is received. [Generated-by: AI]
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces thread-local propagation of StorageMetricsContext to allow resolving operation names for HTTP metrics (such as TTFB) across all HTTP operations. It adds a ThreadLocal storage to StorageMetricsContext and implements makeCurrent() to manage the context scope. Additionally, StorageHttpMetricsInterceptor is updated to resolve operation names dynamically using either the active StorageMetricsContext or a route-based fallback map (ROUTE_OPERATIONS), with support for media uploads and X-HTTP-Method-Override. Extensive unit and integration tests are added to verify these changes. There are no review comments, and I have no feedback to provide.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #14745 (#14745 (comment)) extending
gcp.storage.client.ttfbinstrumentation inStorageHttpMetricsInterceptorbeyond media downloads so all HTTP responses (unary metadata/control requests, direct/multipart uploads, resumable upload sessionopen/chunkPUT/statusqueryrequests, and outer/batch/storage/v1requests) record Time To First Byte when HTTP response headers arrive.Key Changes
StorageMetricsContext&Retrying:StorageMetricsContext.makeCurrent()andStorageMetricsContext.current()combining aThreadLocal<StorageMetricsContext>withotelContext.makeCurrent()in a singleScope(preservingContext.current() == otelContextreference identity and cleaning up theThreadLocalon scope close).metricsContext.makeCurrent()inRetrying.DefaultRetrier.runandRetrying.AttemptOnceRetrier.runso canonicalgcp.storage.operationnames (e.g.,"UpdateBucket"/"UpdateObject"whenStorageImpl.updateexecutes an HTTPGETwith no modified fields) and activeotelContexttrace exemplars propagate automatically toStorageHttpMetricsInterceptor.StorageHttpMetricsInterceptor:isMediaDownloadRequest-only filter onmetrics.recordTtfb(...)inrecordResponse(...), computingdurationSecondsandextractUrlTemplate(request.getUrl())once per response across bothhttp.client.request.durationandgcp.storage.client.ttfb.gcp.storage.operationfromStorageMetricsContext.current()first, falling back toisMediaDownloadRequest("ReadObject"),isMediaUploadRequest("WriteObject"), andROUTE_OPERATIONS(honoringX-HTTP-Method-OverrideforNetHttpTransportPATCHand >2,048-charGETrequests) for context-free transport calls (PCU part hooks,BlobWriteSession,StorageBatch).setIOExceptionHandlerrecordinghttp.client.request.durationonly when no HTTP response is received.StorageMetricsContextTest,RetryingMetricsTest, andStorageHttpMetricsInterceptorTestwith nestedmakeCurrent()scope tests, table-drivenisMediaUploadRequestandresolveOperationName(includingX-HTTP-Method-Overrideand context override) cases, status-code/batch/retry TTFB assertions, and an end-to-endStorageImpl+MockHttpTransporttest covering unary, direct multipart upload, resumable multi-chunk upload (308+200), and trace exemplar propagation.Stack Base
Stacked on #14747 (
feat/storage-response-body-size).